<?php
session_start();
require_once("../config/include_tokyo.inc.php");

//访问权限验证
$userRole = $_SESSION['user_role'];
if($userRole == 1){
	//管理员
}else{
	if($userRole > 0){
		$url = "../index.php?loginError=2";//没权限
	}else{
		$url = "../index.php?loginError=3";//没登录
	}	
	echo "<script language='javascript' type='text/javascript'>";
	echo "window.location.href='$url'";
	echo "</script>";
}



//get post value
$doFlag = $_POST["doFlag"];
$editId = $_POST["editId"];
$roleId = $_POST["role_id"];
$roleName = $_POST["role_name"];





if($doFlag == "save"){
	if($editId > 0){
		$sql = "update roles set role_id=$roleId, role_name='$roleName' where id=$editId ";	
	}else{
		$sql = "insert into roles(role_id,role_name) values ($roleId,'$roleName')";	
	}	
	$db->Execute($sql);
	$strSuccess =  "**********************************<br>"
	."角色保存成功<br>"
	."角色编号: ".$roleId."<br>"
    ."角色名称: ".$roleName."<br>"
	."**********************************<br>"	;	
}else{
	if($editId > 0){
		$sql_currentRole = "select * from roles where id=$editId";
		$result = $db->Execute($sql_currentRole);
		while (!$result->EOF) {
			$roleId = $result->fields['role_id'];
			$roleName = $result->fields['role_name'];
			$result->MoveNext();
		}
  }
}



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<!--Begin:head-->
<? $pageTitle = "角色编辑"; ?>
<?php include("../head.php"); ?>
<!--End:head-->


<body>
<?php include("../topMenu.php"); ?>


<?php include("userMenu.php"); ?>
<form name="inputForm" action="../user/roleInput.php" method="post" onSubmit= "return checkForm()">
<div id="container" >	
<?php
echo $strSuccess;
?>
<div class="grayTable">	
<h4>编辑角色:<?php echo $editId; ?></h4>
<table >
	<tr>
		<td align="right">角色编号:</td>
		<td align="left"><input type="text" name="role_id" id="role_id" size=5 value="<?php echo $roleId; ?>"></td>
	</tr>			
	<tr>
		<td align="right">角色名称:</td>
		<td align="left"><input type="text" name="role_name" id="role_name" size=20 value="<?php echo $roleName; ?>" ></td>
	</tr>
	<tr>
		<td colspan=2 align="right"><input type="submit" value="保存角色"></td>
	</tr>					
</table>	
</div>



</div><!--end container -->
<input type="hidden" name="editId" id="editId" value="<?php echo $editId; ?>" >
<input type="hidden" name="doFlag" id="doFlag" value="save" >
</form>
</body>




</html>

<script>

function checkForm(){
	var roleId = $("#role_id").val();	
	var roleName = $("#role_name").val();	
	if(roleId == ''){
		alert("角色编号不能为空.");
		$("#role_id").focus(); 
		return false;
	}else{
		if(isNaN(roleId)){
			alert("角色编号只能是数字.");
		    $("#role_id").focus(); 
		    return false;
		}
	}
	if(roleName == ''){
		alert("角色名称不能为空.");
		$("#role_name").focus(); 
		return false;
	}
	return true;
}

</script>

